package com.itheima.web.listener;

import com.itheima.autoconfig.AliyunGreenTemplate;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @Author 请不要叫我高司令
 * @Date 2022/3/26 23:27
 * @Version 1.0
 */

@Component
public class MovementStateListener {

    @DubboReference
    private MovementService movementService;

    @Autowired
    private AliyunGreenTemplate aliyunGreenTemplate;

    @RabbitListener(queuesToDeclare = @Queue("tanhua.movement.log"))
    public void listenMovementState(String movementId) {

        System.out.println("动态审核start....");

        Movement movement = movementService.findById(new ObjectId(movementId));

        Boolean checkText = aliyunGreenTemplate.checkText(movement.getTextContent());
        Boolean checkImage = aliyunGreenTemplate.checkImage(movement.getMedias());

        if (checkText && checkImage) {

            movement.setState(1);//通过

        } else {

            movement.setState(2);//拒绝，后面人工复审

        }
        //更新mongo
        movementService.update(movement);
        System.out.println("动态审核end....");

    }


}
